package com.wc.alorithm_blue_bridge._动态规划._数位DP.好数之和;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/26 21:40
 * @description
 * https://www.lanqiao.cn/problems/2226/learning/?page=1&first_category_id=1&name=%E5%A5%BD%E6%95%B0%E4%B9%8B%E5%92%8C&difficulty=10
 */
public class Main {
    /**
     * 数位DP的进阶版
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 15, M = 10;
    static Node[][][][][] f = new Node[N][M][M][M][2];
    static long[] base = new long[N];
    static int[] nums = new int[N];
    static int L, R;

    public static void main(String[] args) {
        L = sc.nextInt();
        R = sc.nextInt();
        base[0] = 1;
        for (int i = 1; i < N; i++) base[i] = base[i - 1] * 10;
        out.println(dp(R) - dp(L - 1));
        out.flush();
    }
    static int len = 1;
    static long dp(int x) {
        len = 1;
        for (int i = 0; i < N; i++) {
            for (int a = 0; a < M; a++) {
                for (int b = 0; b < M; b++) {
                    for (int c = 0; c < M; c++) {
                        f[i][a][b][c][0] = new Node(-1, 0);
                        f[i][a][b][c][1] = new Node(-1, 0);
                    }
                }
            }
        }
        while (x > 0) {
            nums[len++] = x % 10;
            x /= 10;
        }
        return dfs(len - 1, -1, -1, -1, 0, true, false).sum;
    }

    static Node dfs(int i, int a, int b, int c, int exist, boolean limit, boolean num) {
        if (!limit && num && a >= 0 && f[i][a][b][c][exist].cnt >= 0) return f[i][a][b][c][exist];

        if (i == 0) {
            return exist == 1 ? new Node(1, 0) : new Node(0, 0);
        }

        int up = limit ? nums[i] : 9;
        Node res = new Node(0, 0);

        for (int d = 0; d <= up; d++) {
            Node cur = dfs(i - 1, b, c, d, exist == 1 || (a == 2 && b == 0 && c == 2 && d == 2) ? 1 : 0,
                    limit && d == up, num || d > 0);

            res.cnt += cur.cnt;
            res.sum += cur.sum + d * base[i - 1] * cur.cnt;
        }

        if (!limit && a >= 0 && num) f[i][a][b][c][exist] = res;

        return res;
    }

    static class Node {
        Node(int cnt, long sum) {
            this.cnt = cnt;
            this.sum = sum;
        }
        int cnt = 0;
        long sum = 0;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

